package com.huamoxi.config;

import com.huamoxi.filter.JwtRequestFilter;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

@Configuration
public class AuthorizationResourceConfig {

    @Resource
    private JwtRequestFilter jwtRequestFilter;

    @Bean
    public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {

        // 设置自定义请求处理过滤器
        http.addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter.class);

        // 关闭csrf
        http.csrf(AbstractHttpConfigurer::disable);

        // 请求全拦截
        http.authorizeHttpRequests(authorize -> authorize.anyRequest().authenticated());

        return http.build();
    }
}
